package com.example.controller.login;

import com.example.pojo.login.User;
import com.example.service.impl.login.UserServiceImpl;
import com.example.service.login.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 登录模块
 * @author 熊建立
 * @date 2022 11.12
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/getUser")
    public List<User> getUser(){
        return userService.getUser();
    }

    /**
     * 根据账号查用户
     * @param account
     * @return
     */
    @RequestMapping("/getActivity")
    public User getActivity(String account){
        return userService.getEquipFile(account);
    }

    /**
     * 根据用户判断是否登录成功
     * @param user
     * @param password
     * @return
     */
    @PostMapping("/login")
    @ResponseBody
    public Map<String,String> login(@RequestParam("accound")String user,@RequestParam("password")String password){
       Map<String,String> map = new HashMap<>();

        User userByName = userService.getEquipFile(user);
        if(userByName == null){
            map.put("msg","300");
            return map;
        }

        if(!userByName.getPassword().equals(password)){
            map.put("msg","400");
            return map;
        }
        map.put("msg","200");
        return map;
    }
}
